package com.neusoft.ecommerce.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.neusoft.ecommerce.dbhelper.LayuiPager;
import com.neusoft.ecommerce.entity.LogisticsStatus;
import com.neusoft.ecommerce.service.LogisticsStatusService;

/**
 * 
 * @author MaoMao
 *
 */
@RestController
public class logisticsStatusController {
	private final LogisticsStatusService logisticsStatusService;
	
	
	public logisticsStatusController(LogisticsStatusService logisticsStatusService) {
		this.logisticsStatusService = logisticsStatusService;
		
	}
	@GetMapping("/logisticsStatus_page")
    public ModelAndView logisticsStatusServicePage() {
        System.out.println("-----sss______");
         return new ModelAndView("logisticsStatus/logisticsStatus-list");
    }
	
    @RequestMapping("/logisticsStatus/list")
    @ResponseBody
    public LayuiPager<LogisticsStatus> list(@RequestParam(value = "page", defaultValue = "1") String page,
                                    @RequestParam(value = "limit", defaultValue = "10") String limit) {
        System.out.println(page + "" + limit);
        LayuiPager<LogisticsStatus> pager = new LayuiPager<>(Integer.parseInt(page), Integer.parseInt(limit));
        int count = logisticsStatusService.findTotal(pager);
        List<LogisticsStatus> list = logisticsStatusService.findList(pager);
        for (LogisticsStatus logisticsStatus : list) {
            System.out.println(logisticsStatus);
        }
        pager.setData(list);
        pager.setCount(count);
        pager.setCode(0);
        pager.setMsg("");
        return pager;
    }
	
	@GetMapping("/addLogisticsStatus")
    public ModelAndView addAfterSaleService() {
        return new ModelAndView("logisticsStatus/logisticsStatus-add");
    }
	
	
	
	@PostMapping("/logisticsStatus/add")
    public Map<String, Object> add(LogisticsStatus logisticsStatus) {
        System.out.println(logisticsStatus);
        Map<String, Object> map = new HashMap<>(16);
        if (logisticsStatusService.add(logisticsStatus)) {
            map.put("msg","ok");
            map.put("code",0);
        } else {
            map.put("msg","失败");
            map.put("code",1);
        }
        return map;
    }
	
	@GetMapping("/logisticsStatus/edit_page")
    public ModelAndView editPage(LogisticsStatus logisticsStatus, Model model) {
        System.out.println(logisticsStatus);
        LayuiPager<LogisticsStatus> pager = new LayuiPager<>(1,1);
        pager.setCondition(logisticsStatus);
        LogisticsStatus message = logisticsStatusService.findList(pager).get(0);
        System.out.println(message);
        ModelAndView view = new ModelAndView("logisticsStatus/logisticsStatus-edit");
        model.addAttribute("logisticsStatus", message);
        return view;
    }


	@PostMapping("/logisticsStatus/edit")
    public Map<String, Object> edit(LogisticsStatus logisticsStatus) {
        System.out.println(logisticsStatus);
        Map<String, Object> map = new HashMap<>(16);
        if (logisticsStatusService.edit(logisticsStatus)) {
            map.put("msg","ok");
            map.put("code",0);
        } else {
            map.put("msg","失败");
            map.put("code",1);
        }
        return map;
    }
	@PostMapping("/logisticsStatus/delete")
    public Map<String, Object> delete(LogisticsStatus logisticsStatus) {
        System.out.println(logisticsStatus);
        Map<String, Object> map = new HashMap<>(16);
        if (logisticsStatusService.delete(logisticsStatus)) {
            map.put("msg","ok");
            map.put("code",0);
        } else {
            map.put("msg","失败");
            map.put("code",1);
        }
        return map;
    }

}
